import { post, get } from './request'

// api 前缀
const serviceAPi = {
  sysUser: '/ib/sysuser',
  sysRoleMenu: '/ib/sysrolemenu',
  sysMenu: '/ib/sysmenu',
  sysRole: '/ib/sysrole',
  sysMerchant: '/ib/sysmerchant',
  sysUserRole: '/ib/sysuserrole'
}

/*
登录
 */
export function sysUserLogin(params) {
  return post(`${serviceAPi.sysUser}/login`,params)
}

export function getSysUserList(params) {
  return post(`${serviceAPi.sysUser}/list`,params)
}

export function getSysUserById(params) {
  return get(`${serviceAPi.sysUser}/info/${params.id}`,{})
}

export function saveUpdateSysUser(params) {
  if (params.id) {
    return post(`${serviceAPi.sysUser}/update`,params)
  }
  return post(`${serviceAPi.sysUser}/save`,params)
}

export function getRoleRights(roleId) {
  return get(`${serviceAPi.sysRoleMenu}/getRoleRights?roleId=${roleId}`, {})
}

export function getRights(userId) {
  return get(`${serviceAPi.sysRoleMenu}/getRights?userId=${userId}`, {})
}

export function saveRoleMenus(params) {
  return post(`${serviceAPi.sysRoleMenu}/saveRoleRights`, params)
}

export function saveUserRoles(params) {
  return post(`${serviceAPi.sysUserRole}/saveUserRoles`, params)
}

export function saveUpdateMenu(params) {
  let response = ''
  if (params.id) {
    response = post(`${serviceAPi.sysMenu}/update`,params)
  } else {
    response = post(`${serviceAPi.sysMenu}/save`,params)
  }
  return response
}

export function getMenuList(params) {
  return post(`${serviceAPi.sysMenu}/list`,params)
}

export function getRoleList(params) {
  return post(`${serviceAPi.sysRole}/queryJoinList`,params)
}

export function saveUpdateRole(params) {
  if (params.id) {
    return post(`${serviceAPi.sysRole}/update`,params)
  }
  return post(`${serviceAPi.sysRole}/save`,params)
}

export function getMerchantList(params) {
  return post(`${serviceAPi.sysMerchant}/list`, params)
}

export function saveUpdateMerchant(params) {
  if (params.id) {
    return post(`${serviceAPi.sysMerchant}/update`,params)
  }
  return post(`${serviceAPi.sysMerchant}/save`,params)
}

export function getMerchantByDomainName(params) {
  return post(`${serviceAPi.sysMerchant}/getMerchantDomainName`, params)
}
